package sa.com.sure.ejtimaa.components;

import java.io.Serializable;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.List;

import sa.com.sure.ejtimaa.MeetingItemDetail;
import sa.com.sure.ejtimaa.R;
import sa.com.sure.ejtimaa.common.Helper;
import sa.com.sure.ejtimaa.database.MeetingItems;
import sa.com.sure.ejtimaa.model.MeetingInfo;
import sa.com.sure.ejtimaa.model.MeetingItemInfo;
import android.content.Context;
import android.database.SQLException;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

public class MeetingItemsListComponent extends LinearLayout {

	private Context context = null;
	
	private LinearLayout list = null;
	
	private List<MeetingItemInfo> meetingItems = new ArrayList<MeetingItemInfo>();
	
	
	public MeetingItemsListComponent(Context context,AttributeSet attrs){	
		
		super(context,attrs);		
		
		final LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        inflater.inflate(R.layout.meetingitems_list_component, this);
        
        this.context = context;                                      
        
        list =(LinearLayout) this.findViewById(R.id.list) ;
	
	}
	
	
	public void SetData(MeetingInfo item) throws SQLException, ParseException{
			
		meetingItems = MeetingItems.Instance.GetItemsByMeetingId(item.GetMeetingID());
		
		list.removeAllViews();
		
		LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
				
					
		for (final MeetingItemInfo meeting : meetingItems) {
			
			View v = inflater.inflate(R.layout.meetingitems_list_item, null);											
			
			v.setOnClickListener(new OnClickListener(){				
		        public void onClick(View v){
		        
		        	Helper.StartActivity(MeetingItemDetail.class, (Serializable) meeting);
		        	
		        }
		    });
			
			
			TextView tvTitle = (TextView) v.findViewById(R.id.tvTitle);
			TextView tvDescription = (TextView) v.findViewById(R.id.tvDescription);
			
			tvTitle.setText(meeting.GetTitle());
			tvDescription.setText(meeting.GetDescription());
			
			list.addView(v);
		}
		

	}
	

	
}
